import Lbxins from "../../../api/lbxin";
import { withRouter } from "react-router-dom";
import React,{ useEffect, useState,FC } from 'react';

import HorizontalCard from "../component/horizontalCardP"
import { Spin, Empty } from "antd";
import { connect } from "react-redux";
import { ADD_BREAD } from "../../../redux/actions/Breadcrumb";
interface IarticAlListProps {
}

const ArticalList: FC = (props:any):any => {
  console.log(props,'log-props-props')
  
  const shareTopicTitle = props.location.state?props.location.state.shareTopicTitle:null
  const [articalList, setarticalList] = useState([])
  const [articalListLoading, setarticalListLoading] = useState(true)
  useEffect(() => {
    Lbxins.getData(`/default/getShareTopicListById/${props.location.state.id}`)
      .then(res => {
        setarticalListLoading(false)
        setarticalList(res.data)
        // res.data.map((res: { [x: string]: boolean }) => {
        //   return res["CardToolTipShow"] = false;
        // })
      })
      .catch(err => {
        setarticalListLoading(false)
        console.log(err, "log-err")
      });
  }, [])
  const goArticalItem = (info:any) => {
    props.history.push({pathname:'/articalItem',state:{id:info.id,shareTopicTitle:props.location.state?props.location.state.shareTopicTitle:null}})
  }
  return(
    <Spin spinning={articalListLoading}>
      <div className="ArticalList contentBox">
      
        {
          articalList.length>0?articalList.map((res:any) => {
            let props = {...res,shareTopicTitle}
            return <div style={{marginTop:"10px"}} className="lineItem" key={res.id} onClick={()=>goArticalItem(res)}><HorizontalCard articalInfo={props} /></div>
          }): <Empty style={{marginTop:"20%"}} />
        }
      </div>
    </Spin>
  ) ;
};
const mapDispatchToProps = (dispatch: any) => {
  return {
    addBread: (info:any) => {
      console.log(info,'log-info')
      
      dispatch({ type: ADD_BREAD, info })
    }
  }
};
// export default withRouter(mapDispatchToProps,Artical);
export default withRouter(connect(
  null,
  mapDispatchToProps
)(ArticalList));
// export default withRouter(ArticalList);
